import { Controller, Get, Post, Body } from '@nestjs/common';
import { CategoryService } from 'src/services/category/category.service';
import { Category } from 'src/types/category.interface';
import { HttpResponse } from 'src/types/http_response.interface';

@Controller('categories')
export class CategoryController {
    constructor(private readonly categoryService: CategoryService) {

    }
    //GET请求装饰器，无参数
    @Get()
    async findAllActive(): Promise<HttpResponse<Category[]>> {
        const data = await this.categoryService.find({ isActive: true });
        return {
            success: true,
            message: 'All active categories retrieved successfully',
            data
        };
    }
    @Post()
    async create(
        @Body() createCategoryDTO: Category | Category[]
    ): Promise<HttpResponse<Category[] | Category>> {
        const data = await this.categoryService.create(createCategoryDTO);
        return {
            success: true,
            message: 'All active categories retrieved successfully',
            data
        };
    }
    @Get('products')
    async findCategoriesWithProducts(): Promise<HttpResponse<Category[]>> {
        const data = await this.categoryService.findCategoriesWithProducts()
        return {
            success: true,
            message: 'All active categories retrieved successfully',
            data
        };
    }

}
